//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ruoyi.live.tool.commons;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class IMD5 {
    public IMD5() {
    }

    public static Long getMD5(String s) {
        return getMD5(s, "utf-8");
    }

    public static Long getMD5(String s, String charset) {
        try {
            return ICommons.isNullOrEmpty(s) ? null : IConvert.string2long(getMD5(s.getBytes(charset)));
        } catch (UnsupportedEncodingException var3) {
            var3.printStackTrace();
            return null;
        }
    }

    private static String getMD5(byte[] source) {
        String s = null;
        char[] hexDigits = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};

        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(source);
            byte[] tmp = md.digest();
            char[] str = new char[16];
            int k = 0;

            for(int i = 0; i < 16; ++i) {
                byte byte0 = tmp[i];
                str[k++] = hexDigits[(byte0 >>> 4 & 15) % 10];
            }

            s = new String(str);
        } catch (Exception var9) {
            var9.printStackTrace();
        }

        return s;
    }

    public static String crypt(String str) {
        if (str != null && str.length() != 0) {
            StringBuffer hexString = new StringBuffer();

            try {
                MessageDigest md = MessageDigest.getInstance("MD5");
                md.update(str.getBytes());
                byte[] hash = md.digest();

                for(int i = 0; i < hash.length; ++i) {
                    if ((255 & hash[i]) < 16) {
                        hexString.append("0" + Integer.toHexString(255 & hash[i]));
                    } else {
                        hexString.append(Integer.toHexString(255 & hash[i]));
                    }
                }
            } catch (NoSuchAlgorithmException var5) {
                var5.printStackTrace();
            }

            return hexString.toString();
        } else {
            return "";
        }
    }
}
